module nade.image;

import derelict.opengl.gl;

import nade.vector;
import nade.texture;


class Image {
	this(string path)
	{
		_tex = Texture.load(path);
		_tx = Texture._tx;
		_ty = Texture._ty;
	}
	this(string path, string maskPath)
	{
		_tex = Texture.load(path, maskPath);
		_tx = Texture._tx;
		_ty = Texture._ty;
	}
	this(string path, string maskPath, int mx, int my)
	{
		_tex = Texture.load(path, maskPath, mx, my);
		_tx = Texture._tx;
		_ty = Texture._ty;
	}

	void render(const Vector2 size)
	{
		render(-size*0.5, size*0.5);
	}
	void render(const Vector2 from, const Vector2 to)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, _tex);

		glColor3f(1, 1, 1);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 0); glVertex2f(from.x, from.y);
		glTexCoord2f(_tx, 0); glVertex2f(to.x, from.y);
		glTexCoord2f(_tx, _ty); glVertex2f(to.x, to.y);
		glTexCoord2f(0, _ty); glVertex2f(from.x, to.y);
		glEnd();

		glDisable(GL_TEXTURE_2D);
	}

	private {
		GLuint		_tex;
		real		_tx, _ty;
	}
}
